﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ones.ServiceNewsManagement;

namespace Ones.Editorial.Editor
{
    public partial class NewsDisplay : System.Web.UI.Page
    {
        private ServiceNewsManagement.ServiceNewsManagementClient srvNewsMngmt = null;

        #region Events
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                srvNewsMngmt = new ServiceNewsManagementClient();

                rptNewsList.DataSource = srvNewsMngmt.getAllFilterNews(false);
                rptNewsList.DataBind();
            }
        }

        protected void LinkButton_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            Session["newsId"] = e.CommandArgument.ToString();

            switch (e.CommandName.ToString())
            {
                case "EEditNews":
                    Response.Redirect("~/Editorial/Writer/WNewsEdit.aspx");
                    break;
                case "EDeleteNews":
                    srvNewsMngmt = new ServiceNewsManagement.ServiceNewsManagementClient();
                    bool removeNews=srvNewsMngmt.RemoveNews(Convert.ToInt32(Session["newsId"]));
                    if (removeNews)
                    {
                        string alertNewsRemove = "alert('Are you sure you want to remove news?')";
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", alertNewsRemove, true);
                    }
                    break;
            }
        }

        #endregion

        #region Methods
        #endregion
    }
}